﻿<!DOCTYPE html>
<html>
<head>
  <title>ol-ext: control Legends</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <meta name="description" content="iconic font and scalable vector icons for OL3" />
  <meta name="keywords" content="ol3, style, vector, font, fontawesome, icon, maki" />

  <link rel="stylesheet" href="../style.css" />
  <link rel="stylesheet" href="../css/fontmaki.css" />
  <link rel="stylesheet" href="../css/fontmaki2.css" />
  <!-- FontAwesome -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
      
  <!-- jQuery -->
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>

  <!-- Openlayers -->
  <link rel="stylesheet" href="https://openlayers.org/en/latest/css/ol.css" />
  <script type="text/javascript" src="https://openlayers.org/en/latest/build/ol.js"></script>
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL,Object.assign"></script>

  <!-- ol-ext -->
  <link rel="stylesheet" href="../../dist/ol-ext.css" />
  <script type="text/javascript" src="../../dist/ol-ext.js"></script>

  <!-- ol-ext maki and fontawesome defintions used in fontsymbol -->
  <script type="text/javascript" src="../../dist/extra/FontAwesomeDef.js"></script>

  <style>
  .ol-legend ul li.ol-title > div:last-child {
    position:absolute;
    left:0;
    right:0;
    top: 10px
  }
  </style>
</head>
<body >
  <a href="https://github.com/Viglino/ol-ext" class="icss-github-corner"><i></i></a>

  <i clas="fa fa-car" style="position: absolute; top: -100px;"></i>

  <a href="../../index.html">
    <h1>ol-ext: control Legends</h1>
  </a>
  <div class="info">
    The <i>ol/control/Legend</i> computes a legend based on <i>ol/styl/Style</i> and draw it on the map.
    <br/>
    This example display a legend with 2 columns.
  </div>

  <!-- DIV pour la carte -->
  <div id="map" style="width:600px; height:400px;"></div>

<script type="text/javascript">
  
  // Layers
  var layer = new ol.layer.Tile({ source: new ol.source.Stamen({ layer: 'watercolor' }) });
    
  // The map
  var map = new ol.Map ({
    target: 'map',
    view: new ol.View ({
      zoom: 6,
      center: [166326, 5992663]
    }),
    layers: [layer]
  });

  // Define a new legend
  var legend = new ol.control.Legend({ 
    title: 'Legend',
    margin: 5,
    collapsed: false
  });
  map.addControl(legend);

  // Add a new one
  var legend2 = new ol.control.Legend({ 
    title: ' ',
    margin: 5,
    target: legend.element
  });
  map.addControl(legend2);

  var form = { Trianle:3, Square:4, Pentagon: 5, Hexagon: 6 };
  for (var i in form) {
    legend.addRow({ 
      title: i, 
      typeGeom: 'Point',
      style: new ol.style.Style({
        image: new ol.style.RegularShape({
          points: form[i],
          radius: 15,
          stroke: new ol.style.Stroke({ color: [255,128,0,1 ], width: 1.5 }),
          fill: new ol.style.Fill({ color: [255,255,0,.3 ]})
        })
      })
    });
    legend2.addRow({ 
      title: i, 
      typeGeom: 'Point',
      style: new ol.style.Style({
        image: new ol.style.RegularShape({
          points: form[i],
          radius: 15,
          radius2: 7,
          stroke: new ol.style.Stroke({ color: [0,128,255,1 ], width: 1.5 }),
          fill: new ol.style.Fill({ color: [0,255,255,.3 ]})
        })
      })
    });
  }


</script>
  
</body>
</html>
